﻿<%@ Page Title="" Language="C#" MasterPageFile="/Common/Master.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentForm" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentHtml" runat="Server">
    <div class="easyui-layout tableEdit" data-options="fit:true,border:false">
        <div data-options="region:'center',border:false" id="validation" class="validationEngineContainer">
            <div class="z_wrap">
                <ul class="info">
                    <li>
                        <em class='l_name'>登录名称：</em>
                        <div class='r_con1'>
                            <input id='login_name' name='login_name' type='text' class='validate[required]' data-prompt-position='bottomRight' />
                        </div>
                    </li>
                    <li>
                        <em class='l_name'>用户名：</em>
                        <div class='r_con1'>
                            <input id='user_name' name='user_name' type='text' class='validate[required]' data-prompt-position='bottomRight' />
                        </div>
                    </li>
                    <li>
                        <em class='l_name'>密码：</em>
                        <div class='r_con1'>
                            <input id='PassWord' name='PassWord' type='text' class='validate[required]' data-prompt-position='bottomRight' />
                        </div>
                    </li>
                    <li>
                        <em class='l_name'>地址：</em>
                        <div class='r_con1'>
                            <input id='Address' name='Address' type='text' class='validate[required]' data-prompt-position='bottomRight' />
                        </div>
                    </li>
                    <li>
                        <em class='l_name'>头像：</em>
                        <div class='r_con1'>
                            <input id='ImgUrl' name='ImgUrl' type='text' class='validate[required]' data-prompt-position='bottomRight' />
                        </div>
                    </li>
                    <li>
                        <em class='l_name'>性别：</em>
                        <div class='r_con1'>
                            <input id='Gender' name='Gender' type='text' class='validate[required]' data-prompt-position='bottomRight' />
                        </div>
                    </li>
                    <li>
                        <em class='l_name'>手机号：</em>
                        <div class='r_con1'>
                            <input id='Mobile' name='Mobile' type='text' class='validate[required]' data-prompt-position='bottomRight' />
                        </div>
                    </li>
                    <li>
                        <em class='l_name'>备注：</em>
                        <div class='r_con1'>
                            <input id='Remark' name='Remark' type='text' class='validate[required]' data-prompt-position='bottomRight' />
                        </div>
                    </li>
                    <li>
                        <em class='l_name'>创建时间：</em>
                        <div id='AddTime' class='r_con1'>自动</div>
                    </li>
                </ul>
            </div>
        </div>
        <div data-options="region:'south'" style="height: 35px; border-bottom: 0px; border-left: 0px; border-right: 0px;" class="edit_bottom">
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-save'" id="buttonOk">确 定</a>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="$.layerClose(false);">取 消</a>
        </div>
    </div>

    <script type="text/javascript">
        $(function () {
            jQuery('#validation').validationEngine();

            $("#buttonOk").click(function () {

                $.InvokeAjax({
                    url: "Api/V1/System_UserInfo/RepeatedVerificationUserInfo",
                    data: { ID: $.getUrlParamer("guid") == "" ? "00000000-0000-0000-0000-000000000000" : $.getUrlParamer("guid"), login_name: $('#login_name').val() },
                    callBack: function (data) {
                        var obj = $.StrToJson(data).Results;
                        if (obj > 0) {
                            alert("此登录名已存在！");
                            $('#login_name').focus();
                        }
                        else {
                            InsertOrUpdate();
                        }
                    }
                });
            });
            if ($.getUrlParamer("guid") != "") {
                DataBind();
            }
        });

        function DataBind() {
            $.InvokeAjax({
                url: "Api/V1/System_UserInfo/GetUserInfo",
                data: { ID: $.getUrlParamer("guid") },
                callBack: function (data) {
                    var obj = $.StrToJson(data).Results;

                    $.SetValue("ID", obj.ID);
                    $.SetValue("login_name", obj.login_name);
                    $.SetValue("user_name", obj.user_name);
                    $.SetValue("PassWord", obj.PassWord);
                    $.SetValue("Address", obj.Address);
                    $.SetValue("ImgUrl", obj.ImgUrl);
                    $.SetValue("Gender", obj.Gender);
                    $.SetValue("Mobile", obj.Mobile);
                    $.SetValue("Remark", obj.Remark);
                    $.SetValue("AddTime", $.DateFormat(obj.AddTime, 'yyyy-MM-dd HH:mm:ss'));
                }
            });
        }

        function InsertOrUpdate() {
            if (!$('#validation').validationEngine('validate')) { return false; }
            var url = $.getUrlParamer("guid") != "" ? "Api/V1/System_UserInfo/UpdateUserInfo" : "Api/V1/System_UserInfo/AddUserInfo";

            var obj = { ID: $.getUrlParamer("guid") };
            obj.login_name = $.GetValue("login_name");
            obj.user_name = $.GetValue("user_name");

            //var pwd = $.GetMd5($.GetValue("PassWord"));
            //if (obj.PassWord == $.GetValue("PassWord")) {
            //    pwd = obj.PassWord;
            //}
            obj.PassWord = $.GetValue("PassWord");
            obj.Address = $.GetValue("Address");
            obj.ImgUrl = $.GetValue("ImgUrl");
            obj.Gender = $.GetValue("Gender");
            obj.Mobile = $.GetValue("Mobile");
            obj.Remark = $.GetValue("Remark");
            obj.AddTime = $.JsonDateFy($.GetValue("AddTime") == "自动" ? $.GetDateTime() : $.GetValue("AddTime"));
            obj.OrgID = $.getUrlParamer("OrgID");

            $.InvokeAjax({
                url: url,
                data: obj,
                callBack: function (data) {
                    $.layerClose(true);
                }
            });
        }
    </script>
</asp:Content>
